﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="TireService.Web.View.OperatorView.Index" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxRatingControl" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxLoadingPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <!-- Javascript variables used in control -->
    <script language="javascript" type="text/javascript">

        function OnSelectedServiceCarChanged(s) {
            if (ddlServiceCar.GetValue() != null) {
                ddlScheduleDate.PerformCallback(ddlServiceCar.GetValue());
                gvDayPlanBackLog.PerformCallback(ddlServiceCar.GetValue());
            }
        }

        function OnSelectedScheduleDateChanged(s) {
            if (ddlServiceCar.GetValue() != null) {

                var datestring = ddlScheduleDate.GetText().split("-");
                var daystring = datestring[0];
                var monthstring = datestring[1];
                var yearstring = datestring[2].substring(0,4);
                //var scheduleDate = new Date(ddlScheduleDate.GetText());
                //var stringDate = scheduleDate.getDate() + "-" + (1 + scheduleDate.getMonth()) + "-" + scheduleDate.getFullYear();
                var stringDate = daystring + "-" + monthstring + "-" + yearstring;

                window.open('ServiceList.aspx?ServiceCarId=' + ddlServiceCar.GetValue() + "&ScheduleDate=" + stringDate, '_self' ,'Kørselsskema');
            } else {
                alert('Vælg en service bil først');
            }
        }

        // Perform callback that marks selected services as completed and send email to customer
        function MarkServiceAsCompleted(serviceid) {
            var answer = confirm("Færdigmeld sag?")
            if (answer) {
                LoadingPanel.Show();

                // Run callback function to mark service as completed
                callMarkServiceCompleted.PerformCallback(serviceid);
            }
        }

        // Function that runs when server side completed processing of handling markservice as completed
        function OnCallbackMarkServiceCompleted(s, e) {
            gvDayPlanBackLog.PerformCallback(ddlServiceCar.GetValue());

            LoadingPanel.Hide();
        }

        // Function that return error in case callback to server failed
        function CallBackError(s, e) {
            LoadingPanel.Hide();

            alert('Fejl opstod: ' + e.message);
        }

    </script>

    <dx:ASPxLoadingPanel ID="LoadingPanel" Text="Vent venligst..." ClientInstanceName="LoadingPanel" runat="server" Modal="True">
    </dx:ASPxLoadingPanel>

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgOperatorView" alt="" src="~/Images/Medium/wrench.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h1><asp:Label ID="lblOperationView" runat="server" Text="Montørside"></asp:Label></h1>
            </td>
        </tr>
    </table>

    <dx:ASPxCallback ID="callMarkServiceCompleted" ClientInstanceName="callMarkServiceCompleted" runat="server" OnCallback="callMarkServiceCompleted_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackMarkServiceCompleted" />
    </dx:ASPxCallback>

    <table width="100%">
        <tr>
            <td valign="top" style="width:310px">
                <h3>Kørselsskemaer</h3>
                <table width="100%">
                    <tr>
                        <td valign="top">
                            <dx:ASPxComboBox ID="ddlServiceCar" ClientInstanceName="ddlServiceCar" runat="server" Width="300px" Height="40px">
                                <ListBoxStyle Font-Size="Large" />
                                <ItemStyle Font-Size="Large" />
                                <ButtonStyle Font-Size="Large">
                                </ButtonStyle>
                                <ClientSideEvents SelectedIndexChanged="function(s, e) { OnSelectedServiceCarChanged(s); }" />
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <dx:ASPxComboBox ID="ddlScheduleDate" ClientInstanceName="ddlScheduleDate" runat="server" Width="300px" Height="40px" OnCallback="ddlScheduleDate_Callback">
                                <ListBoxStyle Font-Size="Large" />
                                <ItemStyle Font-Size="Large" />
                                <ButtonStyle Font-Size="Large">
                                </ButtonStyle>
                                <ClientSideEvents SelectedIndexChanged="function(s, e) { OnSelectedScheduleDateChanged(s); }" />
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                </table>
                <hr />
                <table width="100%">
                    <tr>
                        <td>
                            <h3>Seneste kunde ratings</h3>
                            <dx:ASPxGridView ID="gvCustomerRating" runat="server" Caption="Kunde anmeldelser" Width="100%"
                                KeyFieldName="ServiceCarScheduleDetailId" AutoGenerateColumns="False" ClientInstanceName="gvCustomerRating">
                                <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" />
                                <SettingsPager AlwaysShowPager="False" PageSize="10" Position="Bottom">
                                    <Summary 
                                        AllPagesText="Sider: {0} - {1} ({2} anmeldelser)" 
                                        Text="Side {0} af {1} ({2} anmeldelser)" />
                                </SettingsPager>
                                <Columns>
                                    <dx:GridViewDataTextColumn FieldName="Name" VisibleIndex="0" Caption="Navn" />
                                    <dx:GridViewDataTextColumn Caption="Postnr" FieldName="ZipCode" VisibleIndex="4" />
                                    <dx:GridViewDataTextColumn Caption="By" FieldName="City" VisibleIndex="5" />
                                    <dx:GridViewDataColumn>
                                        <DataItemTemplate>
                                            <dx:ASPxRatingControl ID="rcCustomerRating" ReadOnly="true" Value='<%# Convert.ToInt32(Eval("Rating")) %>' runat="server">
                                            </dx:ASPxRatingControl>                                          
                                        </DataItemTemplate>
                                    </dx:GridViewDataColumn>
                                </Columns>
                                <SettingsLoadingPanel Mode="ShowOnStatusBar" />
                                <Styles>
                                    <Header ImageSpacing="5px" SortingImageSpacing="5px" />
                                </Styles>
                            </dx:ASPxGridView>
                        </td>
                    </tr>
                </table>
            </td>
            <td valign="top">
                <h3>Ikke færdigmeldte sager</h3>
                <dx:ASPxGridView ID="gvDayPlanBackLog" runat="server" Caption="Backlog" Width="100%"
                    KeyFieldName="ServiceCarScheduleDetailId" AutoGenerateColumns="False" ClientInstanceName="gvDayPlanBackLog"
                    OnCustomCallback="gvDayPlanBackLog_CustomCallback" OnHtmlRowPrepared="gvDayPlanBackLog_HtmlRowPrepared">
                    <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" />
                    <SettingsPager AlwaysShowPager="False" PageSize="25" Position="Bottom">
                        <Summary 
                            AllPagesText="Sider: {0} - {1} ({2} ikke færdigmeldte sager)" 
                            Text="Side {0} af {1} ({2} ikke færdigmeldte sager)" />
                    </SettingsPager>
                    <Settings ShowGroupPanel="True" />
                    <Columns>
                        <dx:GridViewDataTextColumn FieldName="CustomerId" VisibleIndex="0" Caption="Kundenr" />
                        <dx:GridViewDataTextColumn FieldName="ServiceCarScheduleDetailId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ScheduleDate" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ServiceCarId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ToLongitude" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ToLatitude" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="CarId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ContainerId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="ScheduleDetailTypeId" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn FieldName="Note" Visible="false" VisibleIndex="0" />
                        <dx:GridViewDataTextColumn Caption="Navn" FieldName="Name" VisibleIndex="2" />
                        <dx:GridViewDataTextColumn Caption="Postnr" FieldName="ToZipCode" VisibleIndex="4" />
                        <dx:GridViewDataTextColumn Caption="By" FieldName="ToCity" VisibleIndex="5" />
                        <dx:GridViewDataTextColumn Caption="Reg.nr." FieldName="RegistrationNumber" VisibleIndex="7" />
                        <dx:GridViewDataTextColumn Caption="Bil" FieldName="CarBrandDescription" VisibleIndex="7" />
                        <%--<dx:GridViewDataColumn>
                            <DataItemTemplate>
                                <dx:ASPxButton ID="btnInsert" runat="server" ClientInstanceName="btnInsert" Text="Færdigmeld sag" ToolTip="Klik for at færdigmelde sag" AutoPostBack="false"
                                    ClientSideEvents-Click='<%# "function(s, e) { MarkServiceAsCompleted(" + Container.KeyValue + "); }" %>'>
                                </dx:ASPxButton>                                           
                            </DataItemTemplate>
                        </dx:GridViewDataColumn>--%>
                    </Columns>
                    <SettingsLoadingPanel Mode="ShowOnStatusBar" />
                    <Styles>
                        <Header ImageSpacing="5px" SortingImageSpacing="5px" />
                    </Styles>
                </dx:ASPxGridView>
            </td>
        </tr>
        
    </table>
    
    <br />
    

</asp:Content>
